package thread;

import java.util.Random;

public class ThreadDemo18 {
    private static int tmp1=0;
    private static int tmp2=0;
    public static void main(String[] args) throws InterruptedException {
        int arr[]=new int[100_0000];

        for (int i = 0; i < arr.length; i++) {
         Random random=new Random();
         arr[i]=random.nextInt(100);
        }
        Thread t1=new Thread(()->{
            for (int i = 0; i <100_0000 ; i=i+2) {
                tmp1+=arr[i];
            }
        });
        Thread t2=new Thread(()->{
            for (int i = 1; i <100_0000 ; i=i+2) {
                tmp2+=arr[i];
            }
        });
        t1.start();
        t2.start();
        long start=System.currentTimeMillis();
        t1.join();
        t2.join();
        long end=System.currentTimeMillis();
        int result=tmp1+tmp2;
        System.out.println("result:"+result);
        System.out.println("end-start="+(end-start)+"ms");
    }
}
